﻿#include "pch.h"
#include "CSvgObjectService.h"
#include "internalfunctions.h"
#include <gdiplus.h>
using namespace Gdiplus;
#include <math.h> 
#include <vector>
using  std::vector;


CSvgObjectService::CSvgObjectService()
{
}

CSvgObjectService::~CSvgObjectService()
{
}

/////////
//bool CSvgObjectService::DrawSvgEllipseToCDC(CSvgEllipse* pSvgObject, CDC* pdc, CPoint ptStart)
//{
//	bool ret = true;
//	if (pSvgObject == NULL) {
//		return false;
//	}
//
//	return ret;
//}
/////////

/////////
bool CSvgObjectService::DrawSvgTextToCDC(CSvgText* pSvgObject, CDC* pdc, CPoint ptStart)
{
	bool ret = true;
	if (pSvgObject == NULL) {
		return false;
	}

	if (pSvgObject->csText.GetLength() < 1)
	{
		AfxMessageBox(_T("参数不正确!"));
		return false;
	}

	////填充颜色
	Color dFill= SVGColorAnyStringToColor(pSvgObject->fill);
	//边框颜色
	Color dStroke = SVGColorAnyStringToColor(pSvgObject->stroke);


	/*
	CBrush brush,*pOldBrush,*pBrush;
	if(fill.Compare(_T("none"))==0)
	{
		pBrush=CBrush::FromHandle((HBRUSH)GetStockObject(NULL_BRUSH));
		pOldBrush=pdc->SelectObject(pBrush);
	}
	else
	{
		brush.CreateSolidBrush(dFill);
		pOldBrush=pdc->SelectObject(&brush);
	}


	CFont font;
	CFont *pFont;
	if(transform.GetLength()>0)
	{
		font.CreateFont(
			width*scale, //字体高度(旋转后的字体宽度)=56
			height*scale, //字体宽度(旋转后的字体高度)=20
			iAngle, //字体显示角度
			FW_DONTCARE, //nOrientation=0
			10, //字体磅数=10
			FALSE, //非斜体
			FALSE, //无下划线
			FALSE, //无删除线
			DEFAULT_CHARSET, //使用缺省字符集
			OUT_DEFAULT_PRECIS, //缺省输出精度
			CLIP_DEFAULT_PRECIS,//缺省裁减精度
			DEFAULT_QUALITY, //nQuality=缺省值
			DEFAULT_PITCH, //nPitchAndFamily=缺省值
			fontType); //字体名
	}
	else
	{
		font.CreateFont(
			width*scale, //字体高度(旋转后的字体宽度)=56
			height*scale, //字体宽度(旋转后的字体高度)=20
			0, //字体显示角度
			0, //nOrientation=0
			10, //字体磅数=10
			FALSE, //非斜体
			FALSE, //无下划线
			FALSE, //无删除线
			DEFAULT_CHARSET, //使用缺省字符集
			OUT_DEFAULT_PRECIS, //缺省输出精度
			CLIP_DEFAULT_PRECIS,//缺省裁减精度
			DEFAULT_QUALITY, //nQuality=缺省值
			DEFAULT_PITCH, //nPitchAndFamily=缺省值
			fontType); //字体名
	}

	pFont=pdc->SelectObject(&font);

	pdc->SetBkMode(TRANSPARENT);
	if(transform.GetLength()>0)
	{
		pdc->TextOut(transformPt.x*scale,transformPt.y*scale,csText);
	}
	else
	{
		pdc->TextOut(x*scale,y*scale,csText);
	}

	pdc->SelectObject(pOldBrush);

	if(fill.Compare(_T("none"))==0)
	{
		pOldBrush->DeleteObject();
	}
	else
	{
		brush.DeleteObject();
	}
	font.DeleteObject();
	*/

	//
	Graphics graphics(pdc->GetSafeHdc());

	SolidBrush brush1(dFill);

	FontFamily fontfamily1(pSvgObject->fontType);//字体

	const Gdiplus::Font font1(&fontfamily1, pSvgObject->fontSize, FontStyleRegular, UnitPixel);

	PointF  pointf((pSvgObject->x - 8) * pSvgObject->scale + ptStart.x, (pSvgObject->y - 36) * pSvgObject->scale + ptStart.y);
	//PointF类对点进行了封装，这里是指定写字的开始点  

	graphics.SetSmoothingMode(SmoothingModeHighQuality);

	//const StringFormat* pStringFormat =StringFormat::GenericTypographic();

	graphics.DrawString(pSvgObject->csText, -1, &font1, pointf, &brush1);

	return ret;
}

/////////
bool CSvgObjectService::DrawSvgPolygonToCDC(CSvgPolygon* pSvgObject, CDC* pdc, CPoint ptStart)
{
	bool ret = true;
	if (pSvgObject == NULL) {
		return false;
	}
	if (pSvgObject->points.size() < 3)
	{
		return false;
	}

	////填充颜色
	Color dFill = SVGColorAnyStringToColor(pSvgObject->fill);
	//边框颜色
	Color dStroke = SVGColorAnyStringToColor(pSvgObject->stroke);

	/*
	POINT* lpPoints;
	int nCount=points.size()+1;//+1是因为需要闭合图形

	lpPoints = (POINT *)malloc(nCount*sizeof(POINT));
	//分配一块有nCount*sizeof(POINT)大小的空间，然后把该空间首地址给lpPoints

	std::list<CPoint>::iterator it=points.begin();//it指向开始点，list<CPoint>::iterator是正向迭代器
	//list容器
	int n=0;
	for(;it!=points.end();it++)
	{
		lpPoints[n].x=(*it).x*scale;//*it 就是迭代器 it  指向的元素
		lpPoints[n].y=(*it).y*scale;
		n++;
	}
	lpPoints[n].x=(points.front()).x*scale;//第一个元素
	lpPoints[n].y=(points.front()).y*scale;

	pdc->Polygon(lpPoints,nCount);//lpPoints是多边形的所有顶点坐标，nCount顶点个数

	pdc->SelectObject(pOldBrush);
	pdc->SelectObject(pOldPen);

	if(fill.Compare(_T("none"))==0)
	{
		pOldBrush->DeleteObject();
	}
	else
	{
		brush.DeleteObject();
	}
	pen.DeleteObject();
	*/
	//
	Graphics graphics(pdc->GetSafeHdc());
	Pen pen1(dStroke, pSvgObject->strokeWidth);

	//创建点数组，DrawPolygon会按这些点的顺序逐个连接起来  
	Point*  lpPoints;
	int nCount = pSvgObject->points.size();//

	lpPoints = (Point *)malloc(nCount * sizeof(Point));
	//分配一块有nCount*sizeof(POINT)大小的空间，然后把该空间首地址给lpPoints

	std::list<CPoint>::iterator it = pSvgObject->points.begin();//it指向开始点，list<CPoint>::iterator是正向迭代器
	//list容器
	int n = 0;
	for (; it != pSvgObject->points.end(); it++)
	{
		lpPoints[n].X = (*it).x * pSvgObject->scale + ptStart.x;//*it 就是迭代器 it  指向的元素
		lpPoints[n].Y = (*it).y * pSvgObject->scale + ptStart.y;
		n++;
	}

	graphics.SetSmoothingMode(SmoothingModeHighQuality);//设置抗锯齿

	//填充
	SolidBrush  brush1(dFill);
	graphics.FillPolygon(&brush1, lpPoints, nCount);

	// 画边框，也就是闭合直线  
	graphics.DrawPolygon(&pen1, lpPoints, nCount);

	//ALAL 2022.04.21
	free(lpPoints);
	lpPoints = NULL;
	return ret;
}

/////////need to support ptStart
bool CSvgObjectService::DrawSvgRectToCDC(CSvgRect* pSvgObject, CDC* pdc, CPoint ptStart)
{
	bool ret = true;
	if (pSvgObject == NULL) {
		return false;
	}

	////填充颜色
	Color dFill = SVGColorAnyStringToColor(pSvgObject->fill);
	//边框颜色
	Color dStroke = SVGColorAnyStringToColor(pSvgObject->stroke);

	Graphics graphics(pdc->GetSafeHdc());
	SolidBrush brush1(dFill);//填充
	Pen pen1(dStroke, pSvgObject->strokeWidth);

	graphics.SetSmoothingMode(SmoothingModeHighQuality);

	if (pSvgObject->isRoundedCorner == false)
	{
		graphics.FillRectangle(&brush1
			, (INT)(pSvgObject->leftX*pSvgObject->scale)
			, (INT)(pSvgObject->topY*pSvgObject->scale)
			, (INT)(pSvgObject->width*pSvgObject->scale)
			, (INT)(pSvgObject->height*pSvgObject->scale));

		graphics.DrawRectangle(&pen1
			, (INT)(pSvgObject->leftX*pSvgObject->scale)
			, (INT)(pSvgObject->topY*pSvgObject->scale)
			, (INT)(pSvgObject->width*pSvgObject->scale)
			, (INT)(pSvgObject->height*pSvgObject->scale));

	}
	else //有圆角
	{
		// 根据绘图路径填充
		GraphicsPath roundRectPath;
		// 保存绘图路径
		roundRectPath.AddLine((INT)((pSvgObject->leftX + pSvgObject->rx) * pSvgObject->scale)
			, (INT)(pSvgObject->topY*pSvgObject->scale)
			, (INT)((pSvgObject->leftX + pSvgObject->width - pSvgObject->rx) * pSvgObject->scale)
			, (INT)(pSvgObject->topY*pSvgObject->scale)); // 顶部横线

		roundRectPath.AddArc((INT)((pSvgObject->leftX + pSvgObject->width - 2 * pSvgObject->rx)*pSvgObject->scale)
			, (INT)(pSvgObject->topY*pSvgObject->scale)
			, (INT)(2 * pSvgObject->rx*pSvgObject->scale)
			, (INT)(2 * pSvgObject->ry*pSvgObject->scale)
			, 270, 90);// 右上圆角

		roundRectPath.AddLine((INT)((pSvgObject->leftX + pSvgObject->width) * pSvgObject->scale)
			, (INT)((pSvgObject->topY + pSvgObject->ry)*pSvgObject->scale)
			, (INT)((pSvgObject->leftX + pSvgObject->width) * pSvgObject->scale)
			, (INT)((pSvgObject->topY + pSvgObject->height - pSvgObject->ry)*pSvgObject->scale)); // 右侧竖线

		roundRectPath.AddArc((INT)((pSvgObject->leftX + pSvgObject->width - 2 * pSvgObject->rx)*pSvgObject->scale)
			, (pSvgObject->topY + pSvgObject->height - 2 * pSvgObject->ry)*pSvgObject->scale
			,2 * pSvgObject->rx*pSvgObject->scale
			, 2 * pSvgObject->ry*pSvgObject->scale, 0, 90); // 右下圆角

		roundRectPath.AddLine((INT)((pSvgObject->leftX + pSvgObject->width - pSvgObject->rx) * pSvgObject->scale)
			, (pSvgObject->topY + pSvgObject->height)*pSvgObject->scale
			,(pSvgObject->leftX + pSvgObject->rx) * pSvgObject->scale
			, (pSvgObject->topY + pSvgObject->height)*pSvgObject->scale); // 底部横线

		roundRectPath.AddArc((INT)(pSvgObject->leftX*pSvgObject->scale)
			, (pSvgObject->topY + pSvgObject->height - 2 * pSvgObject->ry)*pSvgObject->scale
			,2 * pSvgObject->rx*pSvgObject->scale
			, 2 * pSvgObject->ry*pSvgObject->scale, 90, 90);// 左下圆角

		roundRectPath.AddLine((INT)((pSvgObject->leftX)* pSvgObject->scale)
			, (pSvgObject->topY + pSvgObject->height - pSvgObject->ry)*pSvgObject->scale
			,(pSvgObject->leftX)* pSvgObject->scale
			, (pSvgObject->topY + pSvgObject->ry)*pSvgObject->scale); // 左侧竖线

		roundRectPath.AddArc((INT)(pSvgObject->leftX*pSvgObject->scale)
			, pSvgObject->topY*pSvgObject->scale
			,2 * pSvgObject->rx*pSvgObject->scale
			, 2 * pSvgObject->ry*pSvgObject->scale
			, 180, 90);// 左上圆角


		SolidBrush brush(dFill);
		graphics.FillPath(&brush, &roundRectPath);//填充


		// 画圆角
		//左上
		graphics.DrawArc(&pen1,
			(INT)(pSvgObject->leftX*pSvgObject->scale)
			, pSvgObject->topY*pSvgObject->scale
			,2 * pSvgObject->rx*pSvgObject->scale
			, 2 * pSvgObject->ry*pSvgObject->scale
			, 180, 90);
		//右上
		graphics.DrawArc(&pen1,
			(INT)((pSvgObject->leftX + pSvgObject->width - 2 * pSvgObject->rx)*pSvgObject->scale)
			, pSvgObject->topY*pSvgObject->scale,
			2 * pSvgObject->rx*pSvgObject->scale
			, 2 * pSvgObject->ry*pSvgObject->scale
			, 270, 90);
		//左下
		graphics.DrawArc(&pen1,
			(INT)(pSvgObject->leftX*pSvgObject->scale)
			, (pSvgObject->topY + pSvgObject->height - 2 * pSvgObject->ry)*pSvgObject->scale
			,2 * pSvgObject->rx*pSvgObject->scale
			, 2 * pSvgObject->ry*pSvgObject->scale
			, 90, 90);
		//右下
		graphics.DrawArc(&pen1,
			(INT)((pSvgObject->leftX + pSvgObject->width - 2 * pSvgObject->rx)*pSvgObject->scale)
			,(pSvgObject->topY + pSvgObject->height - 2 * pSvgObject->ry)*pSvgObject->scale
			,2 * pSvgObject->rx*pSvgObject->scale
			, 2 * pSvgObject->ry*pSvgObject->scale
			, 0, 90);

		// 画顶部横线
		graphics.DrawLine(&pen1,
			(INT)((pSvgObject->leftX + pSvgObject->rx - 1) * pSvgObject->scale)
			, (INT)(pSvgObject->topY*pSvgObject->scale)
			, (INT)((pSvgObject->leftX + pSvgObject->width - pSvgObject->rx + 1) * pSvgObject->scale)
			, (INT)(pSvgObject->topY*pSvgObject->scale));
		// 画右侧竖线
		graphics.DrawLine(&pen1,
			(INT)((pSvgObject->leftX + pSvgObject->width) * pSvgObject->scale)
			, (INT)((pSvgObject->topY + pSvgObject->ry - 1)*pSvgObject->scale)
			, (INT)((pSvgObject->leftX + pSvgObject->width) * pSvgObject->scale)
			, (INT)((pSvgObject->topY + pSvgObject->height - pSvgObject->ry + 1)*pSvgObject->scale));
		// 画底部横线
		graphics.DrawLine(&pen1,
			(INT)((pSvgObject->leftX + pSvgObject->width - pSvgObject->rx + 1) * pSvgObject->scale)
			, (INT)((pSvgObject->topY + pSvgObject->height)*pSvgObject->scale)
			, (INT)((pSvgObject->leftX + pSvgObject->rx - 1) * pSvgObject->scale)
			, (INT)((pSvgObject->topY + pSvgObject->height)*pSvgObject->scale));
		// 画左侧竖线
		graphics.DrawLine(&pen1,
			(INT)((pSvgObject->leftX)* pSvgObject->scale)
			, (INT)((pSvgObject->topY + pSvgObject->height - pSvgObject->ry + 1)*pSvgObject->scale)
			,(INT)((pSvgObject->leftX)* pSvgObject->scale)
			,(INT)((pSvgObject->topY + pSvgObject->ry - 1)*pSvgObject->scale));
	}

	return ret;
}

/////////
bool CSvgObjectService::DrawSvgPathToCDC(CSvgPath* pSvgObject, CDC* pdc, CPoint ptStart)
{
	bool ret = true;
	if (pSvgObject == NULL) {
		return false;
	}

	////填充颜色
	Color dFill = SVGColorAnyStringToColor(pSvgObject->fill);
	//边框颜色
	Color dStroke = SVGColorAnyStringToColor(pSvgObject->stroke);


 //边框
//利用循环，记录字母的位置
	int b = 0;
	CString temp;
	vector<int> vec1;
	for (int i = 0; i < pSvgObject->d.GetLength(); i++)
	{
		if (pSvgObject->d.GetAt(i) >= 'A'&& pSvgObject->d.GetAt(i) <= 'Z' || pSvgObject->d.GetAt(i) >= 'a'&& pSvgObject->d.GetAt(i) <= 'z')
		{
			vec1.push_back(i);//i是位置

			temp.Format(_T("%d"), i);

			pdc->TextOutW(b, 0, temp);//打印位置
			b += 20;
		}
	}
	//将字符串分割
	vector<CString> vec2;
	int j; int c = 20;
	CString temp2;
	for (j = 0; j < vec1.size(); j++)
	{
		if (j == vec1.size() - 1)//最后一个字母
		{
			temp2 = pSvgObject->d.Mid(vec1[j], pSvgObject->d.GetLength() - vec1[j]);
		}
		else
		{
			temp2 = pSvgObject->d.Mid(vec1[j], vec1[j + 1] - vec1[j]);
		}
		vec2.push_back(temp2);//存入vec2

		pdc->TextOutW(0, c, temp2);//打印
		c += 20;

	}


	//绘制边框
	Pen pen1(dStroke, pSvgObject->strokeWidth);//颜色，宽度

	Graphics graphics(pdc->GetSafeHdc());


	int curveNumb = 10;
	//int lineNumb = 2;
	PointF *curvePoints = new PointF[curveNumb];//定义曲线点3
	PointF *curvePoints1 = new PointF[curveNumb];//定义曲线点2
	PointF *linePoints = new PointF[10];//定义直线点

	int i = 0;
	for (; i < vec2.size(); i++)//
	{
		if (vec2[i].GetAt(0) == 'M')
		{
			linePoints[i].X = StrToInt(vec2[i].Mid(1, vec2[i].Find(',') - 1));
			linePoints[i].Y = StrToInt(vec2[i].Mid(vec2[i].Find(',') + 1, 3));
		}
		if (vec2[i].GetAt(0) == 'm')
		{
			linePoints[i].X = linePoints[i - 1].X + StrToInt(vec2[i].Mid(1, vec2[i].Find(',') - 1));
			linePoints[i].Y = linePoints[i - 1].Y + StrToInt(vec2[i].Mid(vec2[i].Find(',') + 1, 3));
		}
		if (vec2[i].GetAt(0) == 'H')
		{
			linePoints[i].X = StrToInt(vec2[i].Mid(vec2[i].Find('H') + 1, 3));
			linePoints[i].Y = linePoints[i - 1].Y;
		}
		if (vec2[i].GetAt(0) == 'h')
		{
			linePoints[i].X = linePoints[i - 1].X + StrToInt(vec2[i].Mid(vec2[i].Find('h') + 1, 3));
			linePoints[i].Y = linePoints[i - 1].Y;
		}
		if (vec2[i].GetAt(0) == 'V')
		{
			linePoints[i].X = linePoints[i - 1].X;
			linePoints[i].Y = StrToInt(vec2[i].Mid(vec2[i].Find('V') + 1, 3));
		}
		if (vec2[i].GetAt(0) == 'v')
		{
			linePoints[i].X = linePoints[i - 1].X;
			linePoints[i].Y = linePoints[i - 1].Y + StrToInt(vec2[i].Mid(vec2[i].Find('v') + 1, 3));
		}

		if (vec2[i].GetAt(0) == 'Z' || vec2[i].GetAt(0) == 'z')
		{
			linePoints[i].X = linePoints[0].X;
			linePoints[i].Y = linePoints[0].Y;
		}
		if (vec2[i].GetAt(0) == 'C')//立方贝塞尔曲线C，4个点
		{

			CString curve = vec2[i];
			//curve.Remove(' ');//去除里面的空格		
			curve.Remove('C');
			//pdc->TextOutW(0, 90, curve);
			//分别存储
			for (int jj = 0; jj < 4; jj++)
			{
				if (jj == 0)
				{
					curvePoints[jj].X = linePoints[i - 1].X;
					curvePoints[jj].Y = linePoints[i - 1].Y;
					//curvePoints[j].X = 50;
					//curvePoints[j].Y = 50;
				}
				if (jj == 1 || jj == 2)
				{
					int dou = curve.Find(',');
					//pdc->TextOutW(0, 110, curve.Mid(0, dou));
					curvePoints[jj].X = StrToInt(curve.Mid(0, dou));
					curve.Delete(0, dou + 1);
					int kong = curve.Find(' ');
					//pdc->TextOutW(0, 130, curve.Mid(0, kong));
					curvePoints[jj].Y = StrToInt(curve.Mid(0, kong));
					curve.Delete(0, kong + 1);
				}
				if (jj == 3)
				{
					//pdc->TextOutW(0, 150, curve);
					int dou = curve.Find(',');
					//pdc->TextOutW(0, 110, curve.Mid(0, dou));
					curvePoints[jj].X = StrToInt(curve.Mid(0, dou));
					curve.Delete(0, dou + 1);
					curvePoints[jj].Y = StrToInt(curve);
					//curvePoints[jj].X = 500;
					//curvePoints[jj].Y = 100;
				}
			}


		}
		if (vec2[i].GetAt(0) == 'c')
		{
			CString curve = vec2[i];
			//curve.Remove(' ');//去除里面的空格		
			curve.Remove('c');

			for (int jj = 0; jj < 4; jj++)
			{
				if (jj == 0)
				{
					curvePoints[jj].X = linePoints[i - 1].X;
					curvePoints[jj].Y = linePoints[i - 1].Y;
				}
				if (jj == 1 || jj == 2)
				{
					int dou = curve.Find(',');
					curvePoints[jj].X = curvePoints[0].X + StrToInt(curve.Mid(0, dou));
					curve.Delete(0, dou + 1);
					int kong = curve.Find(' ');
					curvePoints[jj].Y = curvePoints[0].Y + StrToInt(curve.Mid(0, kong));
					curve.Delete(0, kong + 1);
				}
				if (jj == 3)
				{
					int dou = curve.Find(',');
					curvePoints[jj].X = curvePoints[0].X + StrToInt(curve.Mid(0, dou));
					curve.Delete(0, dou + 1);
					curvePoints[jj].Y = curvePoints[0].Y + StrToInt(curve);
				}
			}
		}

		if (vec2[i].GetAt(0) == 'Q')//二次贝塞尔曲线
		{
			CString curve = vec2[i];
			curve.Remove('Q');
			pdc->TextOutW(0, 70, curve);
			for (int jj = 0; jj < 3; jj++)
			{
				if (jj == 0)
				{
					curvePoints1[jj].X = linePoints[i - 1].X;
					curvePoints1[jj].Y = linePoints[i - 1].Y;
				}
				if (jj == 1)
				{
					int dou = curve.Find(',');
					pdc->TextOutW(0, 110, curve.Mid(0, dou));
					curvePoints1[jj].X = StrToInt(curve.Mid(0, dou));
					curve.Delete(0, dou + 1);
					int kong = curve.Find(' ');
					pdc->TextOutW(0, 130, curve.Mid(0, kong));
					curvePoints1[jj].Y = StrToInt(curve.Mid(0, kong));
					curve.Delete(0, kong + 1);
				}
				if (jj == 2)
				{
					//pdc->TextOutW(0, 150, curve);
					int dou = curve.Find(',');
					pdc->TextOutW(0, 150, curve.Mid(0, dou));
					curvePoints1[jj].X = StrToInt(curve.Mid(0, dou));
					curve.Delete(0, dou + 1);
					curvePoints1[jj].Y = StrToInt(curve);
					pdc->TextOutW(0, 170, curve);

				}
			}
			//转换为三次曲线

			curvePoints1[3].X = curvePoints1[2].X;
			curvePoints1[1].X = curvePoints1[0].X + (curvePoints1[1].X - curvePoints1[0].X) * 2 / 3;
			curvePoints1[2].X = curvePoints1[3].X + (curvePoints1[1].X - curvePoints1[3].X) * 2 / 3;

			curvePoints1[3].Y = curvePoints1[2].Y;
			curvePoints1[1].Y = curvePoints1[0].Y + (curvePoints1[1].Y - curvePoints1[0].Y) * 2 / 3;
			curvePoints1[2].Y = curvePoints1[3].Y + (curvePoints1[1].Y - curvePoints1[3].Y) * 2 / 3;



		}

		if (vec2[i].GetAt(0) == 'q')
		{
			CString curve = vec2[i];
			curve.Remove('Q');
			pdc->TextOutW(0, 70, curve);
			for (int jj = 0; jj < 3; jj++)
			{
				if (jj == 0)
				{
					curvePoints1[jj].X = linePoints[i - 1].X;
					curvePoints1[jj].Y = linePoints[i - 1].Y;
				}
				if (jj == 1)
				{
					int dou = curve.Find(',');
					pdc->TextOutW(0, 110, curve.Mid(0, dou));
					curvePoints1[jj].X = curvePoints1[0].X + StrToInt(curve.Mid(0, dou));
					curve.Delete(0, dou + 1);
					int kong = curve.Find(' ');
					pdc->TextOutW(0, 130, curve.Mid(0, kong));
					curvePoints1[jj].Y = curvePoints1[0].Y + StrToInt(curve.Mid(0, kong));
					curve.Delete(0, kong + 1);
				}
				if (jj == 2)
				{
					//pdc->TextOutW(0, 150, curve);
					int dou = curve.Find(',');
					pdc->TextOutW(0, 150, curve.Mid(0, dou));
					curvePoints1[jj].X = StrToInt(curve.Mid(0, dou));
					curve.Delete(0, dou + 1);
					curvePoints1[jj].Y = StrToInt(curve);
					pdc->TextOutW(0, 170, curve);

				}
			}
			//转换为三次曲线

			curvePoints1[3].X = curvePoints1[2].X;
			curvePoints1[1].X = curvePoints1[0].X + (curvePoints1[1].X - curvePoints1[0].X) * 2 / 3;
			curvePoints1[2].X = curvePoints1[3].X + (curvePoints1[1].X - curvePoints1[3].X) * 2 / 3;

			curvePoints1[3].Y = curvePoints1[2].Y;
			curvePoints1[1].Y = curvePoints1[0].Y + (curvePoints1[1].Y - curvePoints1[0].Y) * 2 / 3;
			curvePoints1[2].Y = curvePoints1[3].Y + (curvePoints1[1].Y - curvePoints1[3].Y) * 2 / 3;
		}
	}

	////ALAL
	if (curvePoints != NULL) {
		delete curvePoints;
		curvePoints = NULL;
	}
	if (curvePoints1 != NULL) {
		delete curvePoints1;
		curvePoints1 = NULL;
	}
	if (linePoints != NULL) {
		delete linePoints;
		linePoints = NULL;
	}

	//pdc->TextOutW(310, 90, vec2[4].Mid(vec2[4].Find('v') + 1, 3));

	// 画曲线
	GraphicsPath gPath;

	for (int k = 0; k < 4; k++)
	{
		//gPath.AddLine(linePoints[k].X, linePoints[k].Y, linePoints[k + 1].X, linePoints[k + 1].Y);


	}
	gPath.AddBeziers(&curvePoints1[0], 4);//二次贝塞尔曲线
	//gPath.AddBeziers(&curvePoints[0], 4);//立方贝塞尔曲线

	graphics.SetSmoothingMode(SmoothingModeHighQuality);//设置抗锯齿
	graphics.DrawPath(&pen1, &gPath);//绘制路径


	//
	if (pSvgObject->fill.Compare(_T("none")) == 0)//判断fill里的内容，不填充颜色
	{

	}
	else//填充 
	{
		//通过路径来填充颜色	
		SolidBrush  brush1(dFill);//将16进制颜色值
		graphics.FillPath(&brush1, &gPath);
	}

	return ret;
}

/////////
bool CSvgObjectService::DrawSvgEllipseToCDC(CSvgEllipse* pSvgObject, CDC* pdc, CPoint ptStart)
{
	bool ret = true;
	if (pSvgObject == NULL) {
		return false;
	}

	////填充颜色
	Color dFill = SVGColorAnyStringToColor(pSvgObject->fill);
	//边框颜色
	Color dStroke = SVGColorAnyStringToColor(pSvgObject->stroke);

	Graphics graphics(pdc->GetSafeHdc());
	graphics.SetSmoothingMode(SmoothingModeHighQuality);//设置抗锯齿

	if (pSvgObject->fill.Compare(_T("none")) == 0)//判断fill里的内容，不填充颜色
	{

	}
	else
	{

		SolidBrush  brush1(dFill);//将16进制颜色值
		graphics.FillEllipse(&brush1,
			(INT)((pSvgObject->cX - pSvgObject->rX) * pSvgObject->scale + ptStart.x),
			(INT)((pSvgObject->cY - pSvgObject->rY) * pSvgObject->scale + ptStart.y),
			(INT)(2 * pSvgObject->rX * pSvgObject->scale),
			(INT)(2 * pSvgObject->rY * pSvgObject->scale));
		//填充颜色	


	}
	//使用gdi+绘制圆形边框
	Pen pen1(dStroke, pSvgObject->strokeWidth);//颜色，宽度

	graphics.DrawEllipse(&pen1,
		(INT)((pSvgObject->cX - pSvgObject->rX) * pSvgObject->scale + ptStart.x),
		(INT)((pSvgObject->cY - pSvgObject->rY) * pSvgObject->scale + ptStart.y),
		(INT)(2 * pSvgObject->rX * pSvgObject->scale),
		(INT)(2 * pSvgObject->rY * pSvgObject->scale));
	//绘制圆形边框，   左上角的  x，y，宽度，高度
	return ret;
}


/////////
bool CSvgObjectService::DrawSvgCircleToCDC(CSvgCircle* pSvgObject, CDC* pdc, CPoint ptStart)
{
	bool ret = true;
	if (pSvgObject == NULL) {
		return false;
	}

	//填充颜色
	Color dFill=SVGColorAnyStringToColor(pSvgObject->fill);
	//边框颜色
	Color dStroke = SVGColorAnyStringToColor(pSvgObject->stroke);

	Graphics graphics(pdc->GetSafeHdc());
	graphics.SetSmoothingMode(SmoothingModeHighQuality);//设置抗锯齿
	//绘制填充区域
	if (pSvgObject->fill.Compare(_T("none")) == 0)//判断fill里的内容，不填充颜色
	{

	}
	else
	{

		SolidBrush  brush1(dFill);//16进制颜色值
		graphics.FillEllipse(&brush1,
			(INT)(pSvgObject->centerX * pSvgObject->scale - pSvgObject->radius * pSvgObject->scale + ptStart.x),
			(INT)(pSvgObject->centerY * pSvgObject->scale - pSvgObject->radius * pSvgObject->scale + ptStart.y),
			2 * pSvgObject->radius * pSvgObject->scale,
			2 * pSvgObject->radius * pSvgObject->scale);//填充颜色	


	}
	//绘制圆形边框
	Pen pen1(dStroke, pSvgObject->strokeWidth);//颜色，宽度

	graphics.DrawEllipse(&pen1,
		(INT)(pSvgObject->centerX*pSvgObject->scale - pSvgObject->radius * pSvgObject->scale + ptStart.x),
		(INT)(pSvgObject->centerY*pSvgObject->scale - pSvgObject->radius * pSvgObject->scale + ptStart.y),
		2 * pSvgObject->radius * pSvgObject->scale,
		2 * pSvgObject->radius * pSvgObject->scale);
	//绘制圆形边框，   左上角的  x，y，宽度，高度

	return ret;
}

/////////
bool CSvgObjectService::DrawSvgPolyLineToCDC(CSvgPolyline* pSvgObject, CDC* pdc, CPoint ptStart)
{
	bool ret = true;
	if (pSvgObject == NULL) {
		return false;
	}
	if (pSvgObject->points.size() < 3)
	{
		return false;
	}

	////填充颜色
	Color dFill = SVGColorAnyStringToColor(pSvgObject->fill);
	//边框颜色
	Color dStroke = SVGColorAnyStringToColor(pSvgObject->stroke);

//
	Graphics graphics(pdc->GetSafeHdc());

	SolidBrush brush1(dFill);//填充
	Pen pen1(dStroke, pSvgObject->strokeWidth);

	//创建点数组，DrawPolygon会按这些点的顺序逐个连接起来  
	Point*  lpPoints;
	int nCount = pSvgObject->points.size();//

	lpPoints = (Point *)malloc(nCount * sizeof(Point));
	//分配一块有nCount*sizeof(POINT)大小的空间，然后把该空间首地址给lpPoints

	std::list<CPoint>::iterator it = pSvgObject->points.begin();//it指向开始点，list<CPoint>::iterator是正向迭代器
	//list容器
	int n = 0;
	for (; it != pSvgObject->points.end(); it++)
	{
		lpPoints[n].X = (*it).x * pSvgObject->scale + ptStart.x;//*it 就是迭代器 it  指向的元素
		lpPoints[n].Y = (*it).y * pSvgObject->scale + ptStart.y;
		n++;
	}

	graphics.SetSmoothingMode(SmoothingModeHighQuality);//设置抗锯齿
	graphics.FillPolygon(&brush1, lpPoints, nCount);//填充
	graphics.DrawLines(&pen1, lpPoints, nCount);// 画多边形，也就是闭合直线  

	//ALAL 2022.04.21
	free(lpPoints);
	lpPoints = NULL;

	return ret;
}

/////////
bool CSvgObjectService::DrawSvgLineToCDC(CSvgLine* pSvgObject, CDC* pdc, CPoint ptStart)
{
	bool ret = true;
	if (pSvgObject == NULL) {
		return false;
	}

	//边框颜色
	Color dStroke = SVGColorAnyStringToColor(pSvgObject->stroke);

	//颜色转换，将颜色值转换为英文名称
	//使用gdi+绘制圆形
	Graphics graphics(pdc->GetSafeHdc());
	//int aa = Color::Black-100;
	Pen pen1(dStroke, pSvgObject->strokeWidth);//颜色，宽度

	graphics.SetSmoothingMode(SmoothingModeHighQuality);//设置抗锯齿
	Point mStart, mEnd;
	
	mStart.X = (INT)(pSvgObject->startX * pSvgObject->scale + ptStart.x);
	mStart.Y = (INT)(pSvgObject->startY * pSvgObject->scale + ptStart.y);
	mEnd.X = (INT)(pSvgObject->endX * pSvgObject->scale + ptStart.x);
	mEnd.Y = (INT)(pSvgObject->endY * pSvgObject->scale + ptStart.y);
	graphics.DrawLine(&pen1, mStart, mEnd);//直线

	return ret;
}
